package com.intelligence.device.manager.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.intelligence.device.manager.service.DeviceService;
import com.intelligence.device.manager.service.DeviceThresholdInfoService;
import com.intelligence.entity.pojo.Device;
import com.intelligence.entity.pojo.DeviceThreshold;
import com.intelligence.entity.pojo.DeviceThresholdInfo;
import com.intelligence.entity.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 通用的增删改页面
 *
 * @Author : RulerWood
 * @Data : 2024/6/3 - 15:56
 */
@RestController
@RequestMapping("/device/deviceThresholdInfo")
public class DeviceThresholdInfoController {

    @Autowired
    private DeviceThresholdInfoService deviceThresholdInfoService;

    /**
     * 获取数据列表
     *
     * @param offset   当前页数
     * @param pageSize 每页条目数
     * @return
     */
    @GetMapping("/pageDeviceThresholdInfo")
    public Result<Page<DeviceThresholdInfo>> pageDeviceThresholdInfo(@RequestParam(value = "offset", defaultValue = "1") Integer offset,
                                                                     @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize) {
        return Result.build(deviceThresholdInfoService.page(new Page<>(offset, pageSize)), 200, "获取设备日志列表成功");
    }

    /**
     * 获取数据列表
     *
     * @return
     */
    @GetMapping("/listDeviceThresholdInfo")
    public Result<List<DeviceThresholdInfo>> listDeviceThresholdInfo() {
        return Result.build(deviceThresholdInfoService.list(), 200, "获取设备日志列表成功");
    }

    /**
     * 获取单个对象
     *
     * @param id 对象主键
     * @return
     */
    @GetMapping("/getOneDeviceThresholdInfo/{id}")
    public Result<DeviceThresholdInfo> getOneDeviceThresholdInfo(@PathVariable(value = "id") Integer id) {
        return Result.build(deviceThresholdInfoService.getById(id), 200, "获取设备日志成功");
    }


    /**
     * 数据的新增
     *
     * @param deviceThresholdInfo 保存对象
     * @return
     */
    @PostMapping("/saveDeviceThresholdInfo")
    public Result saveDeviceThresholdInfo(@RequestBody DeviceThresholdInfo deviceThresholdInfo) {
        deviceThresholdInfoService.save(deviceThresholdInfo);
        return Result.build(null, 200, "保存设备日志成功");
    }

    /**
     * 数据的修改
     *
     * @param deviceThresholdInfo 修改对象
     * @return
     */
    @PutMapping("/updateDeviceThresholdInfo")
    public Result updateDeviceThresholdInfo(@RequestBody DeviceThresholdInfo deviceThresholdInfo) {
        deviceThresholdInfoService.updateById(deviceThresholdInfo);
        return Result.build(null, 200, "更新设备日志成功");
    }

    /**
     * 删除某条数据
     *
     * @param id 数据主键
     * @return
     */
    @DeleteMapping("/deleteDeviceThresholdInfo/{id}")
    public Result deleteDeviceThresholdInfo(@PathVariable(value = "id") Integer id) {
        deviceThresholdInfoService.removeById(id);
        return Result.build(null, 200, "删除设备日志成功");
    }

}
